home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / uucp / internal.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-26  |  1.1 KB  |  61 lines

  1. #pragma implementation
  2. #include "internal.h"
  3.  
  4. PUBLIC CONFIG_OBJS::CONFIG_OBJS (CONFIG_FILE &_f)
  5.     : f(_f)
  6. {
  7. }
  8.  
  9. /*
  10.     Read all records from the Permissions file
  11.     Return -1 if any error
  12. */
  13. PUBLIC int CONFIG_OBJS::read()
  14. {
  15.     int ret = -1;
  16.     FILE *fin = f.fopen ("r");
  17.     if (fin != NULL){
  18.         char buf[3000];
  19.         SSTRING comments;
  20.         ret = 0;
  21.         while (fgets_comments(buf,sizeof(buf)-1,fin,comments)!=NULL){
  22.             char err[10000];
  23.             add (newobj(buf,comments,err));
  24.             if (err[0] != '\0') ret = -1;
  25.             comments.setfrom ("");
  26.         }
  27.         fclose (fin);
  28.         if (getnb()==0){
  29.             first_comment.setfrom (comments);
  30.         }else{
  31.             last_comment.setfrom (comments);
  32.         }
  33.     }
  34.     rstmodified();
  35.     return ret;
  36. }
  37.  
  38. PRIVATE CONFIG_OBJ *CONFIG_OBJS::getitem (int no)
  39. {
  40.     return (CONFIG_OBJ*)ARRAY::getitem(no);
  41. }
  42.  
  43. /*
  44.     Write all records from the Poll file
  45. */
  46. PUBLIC int CONFIG_OBJS::write()
  47. {
  48.     int ret = -1;
  49.     FILE *fout = f.fopen ("w");
  50.     if (fout != NULL){
  51.         comment_write (first_comment,fout);
  52.         int n = getnb();
  53.         for (int i=0; i<n; i++) getitem(i)->write (fout);
  54.         comment_write (last_comment,fout);
  55.         ret = fclose (fout);
  56.         rstmodified();
  57.     }
  58.     return ret;
  59. }
  60.  
  61.